/*
 * Copyright (C) 2022 KylinSoft Co., Ltd.
 *
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <https://www.gnu.org/licenses/>.
 */

import QtQuick 2.12
import QtQuick.Window 2.12
import QtQml 2.12
import org.ukui.tablet 1.0

Rectangle {
    color: "transparent";
    property string backgroundImageUrl: screenshot.background
    property var mainContent : null
    property Item backgroundImage: background

    Rectangle {
        id: rect;
        anchors.fill: parent;
        radius: 20
        Image {
            id: background
            width: Screen.width;
            height: Screen.height;
            source: "file://" + backgroundImageUrl;
        }
        opacity: 0;
    }
    ScreenShot {
        id: screenshot;
        width: Screen.width;
        height: Screen.height;
    }

    SequentialAnimation {
        id: pcScaleAnimation;
        ParallelAnimation {
            ScaleAnimator {
                target: screenshot;
                from: 1;
                to: 0.85;
                duration: 500;
                easing.type: Easing.OutQuad;
            }
            OpacityAnimator {
                target: screenshot;
                from: 1;
                to: 0;
                duration: 500;
                easing.type: Easing.OutQuad;
            }
        }
        onFinished: {
            if (mainContent !== null) {
                tabletScaleAnimation.start()
                screenshot.scale = 0
            }
        }
    }

    SequentialAnimation {
        id: tabletScaleAnimation
        ParallelAnimation {
            ScaleAnimator {
                target: mainContent;
                from: 0.85;
                to: 1;
                duration: 500;
                easing.type: Easing.OutQuad;
            }
            OpacityAnimator {
                target: mainContent;
                from: 0;
                to: 1;
                duration: 500;
                easing.type: Easing.OutQuad;
            }
        }
    }

    Component.onCompleted: {
        screenshot.getScreen();
        rect.opacity = 1;
        pcScaleAnimation.start();
        if (mainContent !== null) {
           mainContent.opacity = 0
        }
    }
}
